{extend name="layout:base" /}

{block name="header"}
<link rel="stylesheet" href="/static/js/icheck/minimal/green.css">
{/block}

{block name="body"}

{include file="common:nav" /}

<div class="container bg-fff mt-20 br-5">
    <div class="row pt-15-pb-15">
        <div class="col-lg-12">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation"><a href="{:url('index/database/backup')}">备份</a></li>
                <li role="presentation" class="active"><a href="{:url('index/database/restore')}">还原</a></li>
                <li role="presentation"><a href="{:url('index/database/optimize')}">优化</a></li>
            </ul>
        </div>

        <div class="col-lg-12 mt-10">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>文件名</th>
                        <th width="10%">大小</th>
                        <th width="20%">创建时间</th>
                        <th width="30%">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {volist name="backupFiles" id="file"}
                    <tr>
                        <td>{$file.name}</td>
                        <td>{$file.size}</td>
                        <td>{$file.created_at}</td>
                        <td>
                            <span class="btn-group">
                                <a data-toggle="modal" data-target="#post" class="btn btn-warning btn-sm restore" data-file="{$file.name}">
                                    <i class="fa fa-clock-o" aria-hidden="true"></i> 还原
                                </a>
                                <a onclick="if (confirm('确定删除？')) { location.href = '{:url('database/deleteBackupFile', ['file' => $file['name']])}'; }" class="btn btn-danger btn-sm">
                                    <i class="fa fa-trash" aria-hidden="true"></i> 删除
                                </a>
                            </span>
                        </td>
                    </tr>
                    {/volist}
                </tbody>
            </table>
        </div>

    </div>
</div>

<div class="modal fade" id="post" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">数据库还原</h4>
            </div>
            <form action="{:url('index/database/postRestore')}" method="post">
                {:token()}
                <input type="hidden" name="file" value="">
                <div class="modal-body">
                    还原文件：<b class="restore-file"></b>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-warning" data-dismiss="modal">
                        <i class="fa fa-ban" aria-hidden="true"></i> 取消
                    </button>
                    <button type="submit" class="btn btn-danger">
                        <i class="fa fa-check-square-o" aria-hidden="true"></i> 确定还原
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

{include file="common:footer"}

{/block}

{block name="footer"}
<script>
    require(["jquery"], function ($) {
        $('.restore').bind('click', function () {
            $('.restore-file').text($(this).attr('data-file'));
            $('input[name="file"]').val($(this).attr('data-file'));
        });
    });
</script>
{/block}